home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
pt20pc.zip
/
BUTTON.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-04
|
14KB
|
565 lines
#include "pt.h"
#include "stdlib.h"
/* delay to start scrolling */
static int hsecToWait;
int pascal
/* XTAG:mouseButton */
mouseButton(evhead)
int evhead;
{
extern unsigned char msgBuffer[];
extern union REGS rin, rout;
extern int menuRow, menuCol;
extern struct menuBlock far *menus[];
extern int debug;
extern struct window *selWindow;
extern long selBegin, selEnd;
extern struct window *activeWindow;
extern int scrRows, scrCols;
extern struct event events[];
extern unsigned char buttonVector[];
extern unsigned char toplineVector[];
extern int passEvhead;
extern long passCp;
extern int mousePresent;
extern int menuLine;
extern int helpMode;
extern int descrFileId;
extern int menuShowing;
extern int lastOnTopline;
extern int lastCommand;
extern int isMessage;
extern int searchMode;
extern int smoothScroll;
extern int scrollDelay;
extern unsigned char windowPoints[];
extern struct openFile *files;
extern unsigned char *outOfWindows;
extern int toplineMenu;
struct window *w;
struct window *newW;
int anchorRow, anchorCol, curRow, curCol;
int row1, col1, row2, col2;
int where, buttons, i, n, fid;
int menuNumber, buttonMask, thisShift, thisButton;
long cp, thumbcp, size;
hsecToWait = scrollDelay;
anchorRow = events[evhead].vertical>>3;
anchorCol = events[evhead].horizontal>>3;
thisButton = events[evhead].buttons;
buttonMask = events[evhead].mask;
/* if no buttons down and not a mouse movement command */
/* thit it must be a left over button up event */
/* ignore left over button up events */
if( thisButton == 0 && buttonMask != 1 )
return 0;
if( thisButton == 0 ) {
/* is this the (top or bottom) menu line? */
if( anchorRow != (menuLine > 0 ? 0 : (scrRows-1) ) ) {
/* if we are displaying top line descriptions */
/* then erase them when you leave the top line */
if( helpMode > 1 && lastOnTopline == 1 ) {
lastOnTopline = 0;
msg("", 1);
}
return 0;
}
/* if it is a menu, the figure out which item on it */
if( menuShowing != 0 ) {
n = FindMenuItem( menuShowing, anchorCol );
/* remember the last command selected */
lastCommand = n;
if( helpMode > 1 ) {
readLine(descrFileId, 80L*(long)n,
&msgBuffer[0], 0);
msgBuffer[78] = '\0';
msg(msgBuffer, 1);
lastOnTopline = 1;
}
}
return 0;
}
/* handle things that we need to do every command */
handleTempItems();
switch( thisButton ) {
case 1:
buttons = LEFTBUTTON;
break;
case 2:
buttons = RIGHTBUTTON;
break;
case 3:
case 4:
default:
buttons = BOTHBUTTONS;
break;
}
/* find out what window (if any) and where this mouse was */
xyToPos(&anchorRow, &anchorCol, &where, &cp, &w);
/* set these now that anchorRow and anchorCol are set by xyToPos */
curRow = anchorRow;
curCol = anchorCol;
/* execute the appropriate command for the mouse position */
/* and mouse buttons that were pressed */
switch( buttons+where ) {
/* Any corner, Left => Top/Bottom */
case LEFTBUTTON+UPPERLEFT:
if( waitUp(1) )
goto bothUpperLeft;
else
return command(windowPoints[0], 0, w);
case LEFTBUTTON+LOWERLEFT:
if( waitUp(1) )
goto bothLowerLeft;
else
return command(windowPoints[4], 0, w);
case LEFTBUTTON+UPPERRIGHT:
if( waitUp(1) )
goto bothUpperRight;
else
return command(windowPoints[2], 0, w);
case LEFTBUTTON+LOWERRIGHT:
if( waitUp(1) )
goto bothLowerRight;
else
return command(windowPoints[6], 0, w);
/* Any corner -- Right => Stretch Window */
case RIGHTBUTTON+UPPERLEFT:
row1 = w->row2;
col1 = w->col2;
goto allStretch;
case RIGHTBUTTON+UPPERRIGHT:
row1 = w->row2;
col1 = w->col1;
goto allStretch;
case RIGHTBUTTON+LOWERLEFT:
row1 = w->row1;
col1 = w->col2;
goto allStretch;
case RIGHTBUTTON+LOWERRIGHT:
row1 = w->row1;
col1 = w->col1;
allStretch:
if( getBox(row1, col1, &row1, &col1, &row2, &col2, 1) )
goto noAction;
/* move the window */
if( moveWindow(w, row1, col1, row2, col2) != 0 )
msg("Window too small, not changed", 1);
break;
/* upper border, right button ==> move window */
case RIGHTBUTTON+UPPERBORDER:
row1 = w->row1;
col1 = w->col1;
row2 = w->row2;
col2 = w->col2;
if( getBox(curRow, curCol, &row1, &col1, &row2, &col2, 2) )
goto bothUpper;
/* move the window */
if( moveWindow(w, row1, col1, row2, col2) != 0 )
msg("Window too small, not changed", 1);
break;
/* Upper and Right, Both => Split Window */
case BOTHBUTTONS+UPPERBORDER:
bothUpper:
/* do the action on buttons up */
up2Buttons(&anchorRow, &anchorCol);
/* do not allow splits that are too small */
col2 = w->col2; /* save this for the createWindow */
if( col2 < anchorCol + 10 || w->row2 < anchorRow + 2 ) {
msg("Split window too small, not created", 1);
break;
}
newW = createWindow(files[w->fileId].origName, anchorRow,
anchorCol, w->row2, col2, CRTOP, 0);
if( newW == NULL )
break;
newW->posTopline = w->posTopline;
newW->numTopline = w->numTopline;
newW->indent = w->indent;
redrawWindow(newW);
break;
case BOTHBUTTONS+RIGHTBORDER:
bothRight:
/* do the action on buttons up */
up2Buttons(&anchorRow, &anchorCol);
/* do not allow splits that are too small */
row2 = w->row2; /* save this for the createWindow */
if( anchorCol < w->col1 + 10 || row2 < anchorRow + 2 ) {
msg("Split window too small, not created", 1);
break;
}
newW = createWindow(files[w->fileId].origName, anchorRow,
w->col1, row2, anchorCol, CRTOP, 0);
if( newW == NULL )
break;
row1 = anchorRow+1;
col1 = w->col1+1;
newW->posTopline = xyToWindow(w, &row1, &col1);
newW->numTopline = w->numTopline + anchorRow - w->row1;
newW->indent = w->indent;
redrawWindow(newW);
break;
/* Lower border, Left, Right => Scroll, Both => Thumb */
case LEFTBUTTON+LOWERBORDER:
moreRightScrolling:
if( !smoothScroll && waitUp(1) )
goto bothLower;
if( (where = anchorCol - w->col1 - 1) < 1 )
where = 1;
if( (w->indent -= where) < 0 )
w->indent = 0;
redrawWindow(w);
if( ScrollSomeMore() )
goto moreRightScrolling;
break;
case RIGHTBUTTON+LOWERBORDER:
moreLeftScrolling:
if( !smoothScroll && waitUp(1) )
goto bothLower;
if( (where = anchorCol - w->col1 - 1) < 1 )
where = 1;
w->indent += where;
redrawWindow(w);
if( ScrollSomeMore() )
goto moreLeftScrolling;
break;
case BOTHBUTTONS+LOWERBORDER:
bothLower:
/* do the action on buttons up */
up2Buttons(&anchorRow, &anchorCol);
where = anchorCol - w->col1 - 1;
w->indent = where;
redrawWindow(w);
break;
/* Left border, left and right => scroll, both => thumb */
case LEFTBUTTON+LEFTBORDER:
rev1scr:
if( !smoothScroll && waitUp(1) )
goto bothLeft;
where = anchorRow - w->row1 - 1;
if( where < 1 )
where = 1;
/* set up the screen map and scroll the window */
setMap( w->row1, w->col1, w->row2, w->col2, 1, 0x07);
maskTop(w);
downScroll(w, where);
if( ScrollSomeMore() )
goto rev1scr;
break;
case RIGHTBUTTON+LEFTBORDER:
rev2scr:
if( !smoothScroll && waitUp(1) )
goto bothLeft;
where = anchorRow - w->row1 - 1;
if( where < 1 )
where = 1;
/* set up the screen map and scroll the window */
setMap(w->row1, w->col1, w->row2, w->col2, 1, 0x7);
maskTop(w);
upScroll(w, where);
if( ScrollSomeMore() )
goto rev2scr;
break;
case BOTHBUTTONS+LEFTBORDER:
bothLeft:
/* do the action on buttons up */
up2Buttons(&anchorRow, &anchorCol);
/* remember where we came from */
w->rowLastline = w->numTopline;
fid = w->fileId;
size = fileSize(fid);
n = w->row2 - w->row1 - 2; /* find the size of the window */
where = anchorRow - w->row1 - 1;
if( where < 0 )
where = 0;
else if( where > n )
where = n;
/* handle going to EOF as a special case */
if( where == n ) {
/* this puts the EOF mark on the bottom line */
i = n + 1;
thumbcp